/*
  Detect loop in a linked list 
  List could be empty also
  Node is defined as 
  struct Node
  {
     int data;
     struct Node *next;
  }
*/
int HasCycle(Node* head)
{
    // Complete this function
    // Do not write the main method
    if(head == NULL)
        return 0;
    Node *p1 = head, *p2 = head->next;
    while(p1 != NULL && p2 != NULL && p1 != p2) {
        p1 = p1->next;
        if(p2->next == NULL)
            return 0;
        p2 = p2->next->next;
    }
    return p1 == NULL || p2 == NULL ? 0 : 1;
}